<template>
  <el-dialog title="选择选单号" :visible.sync="visible" width="70%" append-to-body>
    <el-row>
      <el-col :span="24">
        <el-form ref="conditionForm" :model="conditionForm" label-position="left" label-width="100px">
          <el-row :gutter="20" type="flex" class="row-bg">
            <el-col :span="6">
              <el-form-item label="单据编号">
                <el-input v-model="conditionForm.FBillNo" clearable placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="物料代码">
                <el-input v-model="conditionForm.FNumber" clearable placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="物料名称">
                <el-input v-model="conditionForm.FName" clearable placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="规格">
                <el-input v-model="conditionForm.FModel" clearable placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4" class="" style="margin-top: 7px;">
              <el-button size="mini" type="primary" @click="search">查询</el-button>
            </el-col>
          </el-row>
        </el-form>
      </el-col>
      <el-col :span="24" style="width: 100%;height: 4px; border-bottom: 1px dashed #ccc;">
      </el-col>
      <el-col :span="24" class="MarginT_20">
        <el-table id="out-table"
                  :data="dataList"
                  v-loading="listLoading"
                  style="width: 100%"
                  @selection-change="handleSelectionChange"
        >
          <el-table-column
            type="selection"
            fixed="left"
            width="50">
          </el-table-column>
          <el-table-column
            type="index"
            fixed="left"
            width="50">
          </el-table-column>
          <el-table-column
            property="FBillNo"
            label="单据编号"
            width="150"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            property="FDate"
            label="日期"
            width="150"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            property="FNumber"
            label="物料代码"
            width="150"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            property="FName"
            label="物料名称"
            width="150"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            property="Model"
            label="规格"
            width="150"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            property="funit"
            label="单位"
            width="150"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            property="FAuxQty"
            label="数量"
            width="150"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            property="FAuxTaxPrice"
            label="单价">
          </el-table-column>
          <el-table-column
            property="FAllAmount"
            label="总价"
            width="100"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            property="jhtime"
            label="交货日期"
            width="100"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            property="FEntrySelfP0275"
            label="采购特殊要求"
            width="120"
            show-overflow-tooltip>
          </el-table-column>
        </el-table>
      </el-col>
      <el-col :span="24" class="TextAlignR MarginT_20" v-if="dataList.length > 0">
        <el-pagination
          @current-change="handleCurrentChange"
          :current-page.sync="curPage"
          :page-size="10"
          layout="prev, pager, next, jumper"
          :total="sum">
        </el-pagination>
      </el-col>
    </el-row>
    <div slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" @click="handleOk">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {mapState} from 'vuex'
import { getQueryParams } from '../util/utils'

export default {
  name: 'ChooseSupplyModal',
  data () {
    return {
      curPage: 1,
      sum: 0,
      visible: false,
      listLoading: false,
      conditionForm: {},
      dataList: [],
      selectionRows: []
    }
  },
  computed: {
    ...mapState({
      fsupplierid: state => state.fsupplierid
    })
  },
  methods: {
    show () {
      this.visible = true
      this.getList()
    },
    search () {
      this.curPage = 1
      this.getList()
    },
    handleCurrentChange () {
      this.getList()
    },
    getList () {
      this.listLoading = true
      let formatData = getQueryParams({...this.conditionForm, ...{fsupplierid: this.fsupplierid}}, {current: this.curPage, pageSize: 10})
      this.Http.get('/yw_supplier_user/ywSupplierUser/serPoorderList', formatData
      ).then(res => {
        if (res.data.success) {
          this.dataList = res.data.result.records
          this.sum = res.data.result.total
          this.listLoading = false
        }
      }).catch((error) => {
        console.log(error)
        this.listLoading = false
      })
    },
    handleSelectionChange (selectionRows) {
      this.selectionRows = selectionRows
    },
    handleOk () {
      let FBillNo = this.selectionRows.length ? this.selectionRows[0].FBillNo : ''
      // let filtArr = this.selectionRows.filter(item => item.FBillNo !== FBillNo)
      if (!this.selectionRows.length) {
        this.$message.warning('请选择选单号！')
        return false
      }
      // if (filtArr.length) {
      //   this.$message.warning('请选择同一个单据编号！')
      //   return false
      // }
      this.$emit('chooseSupplyBack', {selectionRows: this.selectionRows})
      this.visible = false
    }
  }
}
</script>

<style scoped>

</style>
